import 'package:ride_rex/service/user_service.dart';
import 'package:uuid/uuid.dart';

const String jsonKeyCommentBeanText = 'text';
const String jsonKeyCommentBeanAudioFileName = 'audio_file_name';
const String jsonKeyCommentBeanAudioSize = 'audio_size';
const String jsonKeyCommentBeanAudioDuration = 'audio_duration';
const String jsonKeyCommentBeanRecordId = 'record_id';
const String jsonKeyCommentBeanSenderName = 'sender_name';
const String jsonKeyCommentBeanSenderAvatar = 'sender_avatar';
const String jsonKeyCommentBeanIsLike = 'is_like';

class CommentBean {
  String? text;
  String? audioFileName;
  int? audioSize;
  int? audioDuration;
  String? recordId;
  String? senderName;
  String? senderAvatar;
  String? isLike;

  bool isPlaying = false;

  CommentBean({
    this.text,
    this.audioFileName,
    this.audioSize,
    this.audioDuration,
    this.recordId,
    this.senderName,
    this.senderAvatar,
    this.isLike,
  });

  ///文字评论
  CommentBean.text({required this.text})
      : audioFileName = '',
        recordId = const Uuid().v1(),
        senderName = UserService.instance.notifierOfMineInfo.value.nickname,
        senderAvatar = UserService.instance.notifierOfMineInfo.value.avatarThumbUrl;

  ///语音评论
  CommentBean.audio({
    required this.audioFileName,
    required this.audioSize,
    required this.audioDuration,
  })  : text = '',
        recordId = const Uuid().v1(),
        senderName = UserService.instance.notifierOfMineInfo.value.nickname,
        senderAvatar = UserService.instance.notifierOfMineInfo.value.avatarThumbUrl;

  CommentBean.fromJson(dynamic json) {
    if (json[jsonKeyCommentBeanText] is String) {
      text = json[jsonKeyCommentBeanText];
    }
    if (json[jsonKeyCommentBeanAudioFileName] is String) {
      audioFileName = json[jsonKeyCommentBeanAudioFileName];
    }
    if (json[jsonKeyCommentBeanAudioSize] is int) {
      audioSize = json[jsonKeyCommentBeanAudioSize];
    }
    if (json[jsonKeyCommentBeanAudioDuration] is int) {
      audioDuration = json[jsonKeyCommentBeanAudioDuration];
    }
    if (json[jsonKeyCommentBeanRecordId] is String) {
      recordId = json[jsonKeyCommentBeanRecordId];
    }
    if (json[jsonKeyCommentBeanSenderName] is String) {
      senderName = json[jsonKeyCommentBeanSenderName];
    }
    if (json[jsonKeyCommentBeanSenderAvatar] is String) {
      senderAvatar = json[jsonKeyCommentBeanSenderAvatar];
    }
    if (json[jsonKeyCommentBeanIsLike] is String) {
      isLike = json[jsonKeyCommentBeanIsLike];
    }
  }

  Map<String, dynamic> toJson() {
    final Map<String, dynamic> _data = <String, dynamic>{};
    _data[jsonKeyCommentBeanText] = text;
    _data[jsonKeyCommentBeanAudioFileName] = audioFileName;
    _data[jsonKeyCommentBeanAudioSize] = audioSize;
    _data[jsonKeyCommentBeanAudioDuration] = audioDuration;
    _data[jsonKeyCommentBeanRecordId] = recordId;
    _data[jsonKeyCommentBeanSenderName] = senderName;
    _data[jsonKeyCommentBeanSenderAvatar] = senderAvatar;
    _data[jsonKeyCommentBeanIsLike] = isLike;
    return _data;
  }
}
